﻿using System;
using Nydus.Model.Entities;
using Nydus.WebForms.Frontend.Helpers;
using Nydus.WebForms.Frontend.Presenters;
using Nydus.WebForms.Frontend.ViewModels;
using Nydus.WebForms.Frontend.Views;
using Nydus.WebForms.FrontendModel;

namespace Nydus.WebForms.Frontend.Pages
{
    [PresenterType(typeof(SelectCustomerPresenter))]
    public partial class SelectCustomer : BasePage<SelectCustomerViewModel>, ISelectCustomerView
    {
        protected override void BindModelData()
        {
            this.Model.Customer = new Customer()
            {
                Id = Parser.ParseIdString(txtCustomerId.Text),
                Name = txtCustomerName.Text
            };
            this.Model.PageNumber = Int32.Parse(hdnPageNumber.Value);
        }

        #region Events

        public event EventHandler Search;

        public event EventHandler PrevPage;

        public event EventHandler NextPage;

        public event EventHandler ChooseCustomer;

        #endregion

        #region Event handlers

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (Search != null)
                Search(this, EventArgs.Empty);
        }

        protected void btnPrevPage_Click(object sender, EventArgs e)
        {
            if (PrevPage != null)
                PrevPage(this, EventArgs.Empty);
        }

        protected void btnNextPage_Click(object sender, EventArgs e)
        {
            if (NextPage != null)
                NextPage(this, EventArgs.Empty);
        }

        protected void btnChooseCustomer_Click(object sender, EventArgs e)
        {
            if (ChooseCustomer != null)
                ChooseCustomer(this, EventArgs.Empty);
        }

        #endregion
    }
}